<?php

namespace App\RpcProvider;

use App\Service\HscoinBalanceService;
use App\Service\HscoinStatsService;
use App\Service\PriceLogService;
use Hyperf\RpcServer\Annotation\RpcService;
use function Hyperf\Support\env;
use Hyperf\Di\Annotation\Inject;

define('RpcServiceName', 'yaoli-service-rpc-' . env('APP_NAME', 'appname'));

#[RpcService(name: RpcServiceName, protocol: 'jsonrpc-http', server: "jsonrpc-http", publishTo: "nacos")]
/**
 * 服务提供者 示例
 */
class CalculatorService
{
    #[inject]
    private PriceLogService $logService;

    /**
     *
     * @return void
     */
    function getMyHscoin()
    {
        return [
            'my_gold' => mt_rand(100, 1000), // 我的金豆
            'today_get' => mt_rand(100, 1000), // 今日获得金豆数
            'current_worth' => 0.00, // 当前金豆价值
            'accumulate_gold' => 0.00,//累计金豆数
        ];
        return $rs = $this->hscoinBalanceservice->getCache();
    }

    function getPrice(): float
    {
        $rs = $this->logService->getPriceInfo();
        return $rs['price'] ?? 0;
    }

}
